﻿@model IEnumerable<StoreHoursDomain.Entity.Store>
@* DXCOMMENT: Configure GridView *@
@Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "GridView";
        settings.CallbackRouteValues = new { Controller = "Hours", Action = "Summary" };
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.SettingsPager.PageSize = 600;
        settings.Settings.ShowVerticalScrollBar = true;
        settings.Settings.VerticalScrollableHeight = 850;
        settings.SettingsBehavior.ConfirmDelete = true;

        settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

        //settings.Columns.Add(col =>
        //{
        //    col.Caption = "Email";
        //    col.Name = "Email Store";
        //    col.EditCellStyle.BackgroundImage.ImageUrl =  "~/JSDatePicker/img/boxTopPx.png";
        //});     
        
        settings.Columns.Add(col =>
        {
            col.FieldName = "Name";

        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Monday";
            col.FieldName = "CurrentHours.MondayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Tuesday";
            col.FieldName = "CurrentHours.TuesdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Wednesday";
            col.FieldName = "CurrentHours.WednesdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Thursday";
            col.FieldName = "CurrentHours.ThursdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Friday";
            col.FieldName = "CurrentHours.FridayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Saturday";
            col.FieldName = "CurrentHours.SaturdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Sunday";
            col.FieldName = "CurrentHours.SundayHours.DisplayFormat";
        });

        settings.HtmlDataCellPrepared = (sender, e) =>
        {
            if (e.DataColumn.EditFormCaption == "Email") e.Cell.Attributes.Add("onclick", string.Format("OnEmailClick('{0}');", ((WebUI.Models.StoreViewModel) ((MVCxGridView) sender).GetRow(e.VisibleIndex)).ID));
            else e.Cell.Attributes.Add("onclick", string.Format("OnCellClick('{0}');", ((WebUI.Models.StoreViewModel) ((MVCxGridView) sender).GetRow(e.VisibleIndex)).ID));
        };
        
        settings.SettingsEditing.Mode = GridViewEditingMode.Inline;
        settings.KeyFieldName = "ID";
    }).Bind(Model.Select(store => WebUI.Models.StoreViewModel.GetStoreViewModel(store))).GetHtml()


<script type="text/javascript">
    function OnCellClick(id) {
        window.location = "@Url.Action("Details", "Hours")/" + id;
    }
    function OnEmailClick(id) {
        window.location = "@Url.Action("Email", "Hours")/" + id;
    }
</script>